package com.by;

import com.by.mapper.sys.UserMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.session.RowBounds;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import javax.management.Query;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
import java.util.function.IntBinaryOperator;

public class PageTests {

    @Autowired
    UserMapper userMapper;

    /**
     * 使用数据库本身的分页
     */
  /*  @Test
    public void testMysql(){
        int page=2;//显示第几页数据
        int pageSize=2;//每页显示的记录数
        //计算当前页从第几条记录开始
        int offset=(page-1)*pageSize;

        Map map=new HashMap();
        map.put("offset",offset);
        map.put("pageSize",pageSize);

        List list=userMapper.query(map);
        //总记录数
        long total=userMapper.queryCount(map);

        //换算总页数
        long count=total%pageSize==0?(total/pageSize):(total/pageSize+1);
        //将所有的结果封装起来返回
        System.out.println(list.size());
    }


    @Test
    public void testRowBounds(){
        int page=2;//显示第几页数据
        int pageSize=2;//每页显示的记录数
        //计算当前页从第几条记录开始
        int offset=(page-1)*pageSize;
           List list=userMapper.queryUser(new RowBounds(offset,pageSize));
        System.out.println(list.size());
    }*/

    @Test
    public void testPageHelper(){
     PageHelper.startPage(2,2);
      List list=  userMapper.query(null);
      Page page= (Page) list;
        System.out.println("总记录数："+page.getTotal());
        System.out.println("总页数"+page.getPages());
      System.out.println("----------"+ page.getTotal());
    }
    @Test
    public void test1(){
        Runnable q = () -> {

        };
        ;

    }

    @Test
    public void test12() {
       new LinkedBlockingQueue<>();
        ThreadPoolExecutor t = new ThreadPoolExecutor(5,10,100, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<>(10));
        System.out.println(Integer.MAX_VALUE);
    }
}